package com.akuhome.resource.service.need;

import com.akuhome.resource.DO.need.*;
import com.akuhome.resource.dao.NeedDao;
import com.akuhome.resource.enums.NeedStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FoodNeedService implements NeedService<FoodNeed> {
    @Autowired
    private NeedDao needDao;

    @Override
    public void insertNeed(FoodNeed need) {
        needDao.insertFoodNeed(need);
    }

    @Override
    public void insertNeedDetails(Map<String, Object> insertMap) {
        needDao.insertFoodNeedDetails(insertMap);
    }

    @Override
    public FoodNeed findNeedByProjectUid(String projectUid) {
        return needDao.findFoodNeedByProjectUid(projectUid);
    }

    @Override
    public void updateNeedStatusByProjectUid(String uid, NeedStatus needType) {
        needDao.updateFoodNeedStatusByProjectUId(uid,needType);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateNeed(FoodNeed need) {
        needDao.updateFoodNeed(need);
        HashMap<String,Object> updateMap = new HashMap<>();
        updateMap.put("id",need.getId());
        updateMap.put("detailList",need.getDetailList());
        needDao.updateFoodNeedDetails(updateMap);
    }
}
